# Copyright: (C) 2010 RobotCub Consortium
# Author: Lorenzo Natale
# CopyPolicy: Released under the terms of the GNU GPL v2.0.

if (NOT ICUB_FOUND)
  message(STATUS "Using iCub from build tree")

  set(ICUB_VERSION @ICUB_VERSION@)
  # If YARP_LIBRARIES has been valorized by a previous call of find_package(YARP)
  # in user CMakelists.txt save it in temporary variable to restore it later.
  if(DEFINED YARP_LIBRARIES)
    set(_temp_yarp_libs ${YARP_LIBRARIES})
  endif()

  include(CMakeFindDependencyMacro)
  find_dependency(YCM @YCM_REQUIRED_VERSION@ REQUIRED)
  find_dependency(YARP @YARP_REQUIRED_VERSION@ REQUIRED COMPONENTS os conf sig dev math gsl)

  include("@CMAKE_BINARY_DIR@/@EXPORT_INCLUDE_FILE@")
  include("@CMAKE_BINARY_DIR@/@EXPORT_CONFIG_FILE@")

  set(ICUB_LIBRARIES "@ICUB_TARGETS@" CACHE INTERNAL "List of iCub libraries")
  set(ICUB_MODULE_PATH "@ICUB_MODULE_PATH@" CACHE INTERNAL "iCub cmake scripts directory")
  set(ICUB_LINK_FLAGS "@ICUB_LINK_FLAGS@" CACHE INTERNAL "List of iCub linker options")
  set(ICUB_LINK_DIRECTORIES "@ICUB_LINK_DIRECTORIES@")

  # This is not ideal and should be removed. At the moment
  # only needed by OpenCV
  link_directories(${ICUB_LINK_DIRECTORIES})
  set (ICUB_FOUND TRUE)
  if(DEFINED _temp_yarp_libs)
    list(APPEND YARP_LIBRARIES ${_temp_yarp_libs})
    list(REMOVE_DUPLICATES YARP_LIBRARIES)
  endif()
endif (NOT ICUB_FOUND)
